﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ueEngine.Biz.Core.ExServer.WorkPool.WorkHandle;
using ueEngine.Biz.Core.ExServer.WorkPool.WorkHandle.Email;
using ueEngine.Biz.Core.ExServer.WorkPool.WorkHandle.FullSearch;

namespace ueEngine.Biz.Core.ExServer.WorkPool
{
    internal class WorkFactory<T>
    {
        static Dictionary<WorkType, KeyValuePair<IWorkHandle<T>, Type>> dict = new Dictionary<WorkType, KeyValuePair<IWorkHandle<T>, Type>>();
        static WorkFactory()
        {
            dict.Add(WorkType.email_for_register_c,
                new KeyValuePair<IWorkHandle<T>, Type>(
                    new EmailForCRegisterHandle<T>(),
                    typeof(AccountEmail)));
            dict.Add(WorkType.email_for_register_b,
                new KeyValuePair<IWorkHandle<T>, Type>(
                    new EmailForBRegisterHandle<T>(),
                    typeof(AccountEmail)));
            dict.Add(WorkType.email_for_resetpassword,
                new KeyValuePair<IWorkHandle<T>, Type>(
                    new EmailForResetPwdHandle<T>(),
                    typeof(AccountEmail)));
            dict.Add(WorkType.email_for_advertisement,
                new KeyValuePair<IWorkHandle<T>, Type>(
                    new EmailForAdvHandle<T>(),
                    typeof(AdvertisementEmail)));
            dict.Add(WorkType.email_for_requestresume,
                new KeyValuePair<IWorkHandle<T>, Type>(
                    new EmailForJobRequest<T>(),
                    typeof(RequestResumeEmail)));
            dict.Add(WorkType.email_for_recruitmentexamined,
                new KeyValuePair<IWorkHandle<T>, Type>(
                    new EmailForRecruitmentExamined<T>(),
                    typeof(AutoPushMessage))); 
            dict.Add(WorkType.index_position,
                new KeyValuePair<IWorkHandle<T>, Type>(
                    new IndexPositionHandle<T>(),
                    typeof(List<PositionItem>)));
        }
        private static IWorkHandle<T> GetHandleWithParam(WorkType type, T context)
        {
            var item = dict[type];
            if (item.Value == typeof(T))
            {
                return item.Key as IWorkHandle<T>;
            }
            return null;
        }
        public static IWorkHandle<T> GetHandle(WorkType type, T context)
        {
            return GetHandleWithParam(type, context);
        }
    }
}
